package com.kika.obwiki.websocket;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 异步WebSocket服务类
 * 用于异步发送WebSocket消息，避免阻塞主业务线程
 */
@Service
public class WsServiceAsync {

  private static final Logger LOG = LoggerFactory.getLogger(WsServiceAsync.class);

  @Resource
  public WebSocketServer webSocketServer;

  /**
   * 异步发送WebSocket消息
   * 
   * @param message 要发送的消息
   */
  @Async("asyncExecutor")
  public void sendInfo(String message) {
    LOG.info("异步发送WebSocket消息，线程：{}，消息：{}", Thread.currentThread().getName(), message);
    webSocketServer.sendInfo(message);
  }
}